#encoding:utf-8
__author__ = 'administrator'
import sys
import xml.etree.cElementTree as ET
from xml.etree.cElementTree import  Element,SubElement


reload(sys)
sys.setdefaultencoding('gbk')
data='''
<data>
    <country name="Liechtenstein">
        <rank>1</rank>
        <year>2008</year>
        <gdppc>141100</gdppc>
        <neighbor name="Austria" direction="E"/>
        <neighbor name="Switzerland" direction="W"/>
    </country>
    <country name="Singapore">
        <rank>4</rank>
        <year>2011</year>
        <gdppc>59900</gdppc>
        <neighbor name="Malaysia" direction="N"/>
    </country>
    <country name="Panama">
        <rank>68</rank>
        <year>2011</year>
        <gdppc>13600</gdppc>
        <neighbor name="Costa Rica" direction="W"/>
        <neighbor name="Colombia" direction="E"/>
    </country>
</data>'''

data2='''<line_870>
	<nodes>
		<stop up="1" start="1">
			<name>aaa</name>
			<stop_sn>1</stop_sn>
			<bj_stop_sn>1</bj_stop_sn>
			<stop_code>st00000</stop_code>
			<longitude>121.29685</longitude>
			<latitude>31.14369</latitude>
			<radius>70</radius>
		</stop>
		<stop up="1">
			<name>bbb</name>
			<stop_sn>2</stop_sn>
			<bj_stop_sn>2</bj_stop_sn>
			<stop_code>st00000</stop_code>
			<longitude>121.29762</longitude>
			<latitude>31.14359</latitude>
			<radius>70</radius>
		</stop>
		<stop up="1">
			<name>ccc</name>
			<stop_sn>3</stop_sn>
			<bj_stop_sn>3</bj_stop_sn>
			<stop_code>st00000</stop_code>
			<longitude>121.30021</longitude>
			<latitude>31.14066</latitude>
			<radius>70</radius>
		</stop>
	</nodes>
</line_870>
'''

tree=ET.fromstring(data2)
print tree

tree2 = ET.parse('e:/870/its_line2.xml')
root2 = tree2.getroot()

#tree=ET.ElementTree(file='C:/ftp/file1.xml')

# for ele in tree.iter():
#     print ele

# for country in tree.findall('country'):
#     rank = country.find('rank').text
#     name = country.get('name')
#     print name, rank


for country in root2.findall('nodes'):
    for country2 in country.findall('stop'):
        rank = country2.find('name').text
        name = country2.find('longitude').text
        print name, rank

#for ele in tree.iter(tag='stop'):
    #print ele
    #print ele.tag, '  +   ',ele.attrib
#
# root = ET.Element('line_NBX')
# a=ET.SubElement(root, 'nodes')
# b=ET.SubElement(a,'stop')
# c=ET.SubElement(b,'name')
# c.text='nqqcz'
# d=ET.SubElement(b,'stop_sn')
# d.text='1'
# e=ET.SubElement(b,'bj_stop_sn')
# e.text='1'
# f=ET.SubElement(b,'longitude')
# f.text='121.28475'
# g=ET.SubElement(b,'latitude')
# g.text='30.55071'
# h=ET.SubElement(b,'radius')
# h.text='70'
# l=ET.SubElement(a,'stop')
# c=ET.SubElement(l,'name')
# c.text='nqqcz'
# d=ET.SubElement(l,'stop_sn')
# d.text='1'
# e=ET.SubElement(l,'bj_stop_sn')
# e.text='1'
# f=ET.SubElement(l,'longitude')
# f.text='121.28475'
# g=ET.SubElement(l,'latitude')
# g.text='30.55071'
# h=ET.SubElement(l,'radius')
# h.text='70'
#
# print ET.tostring(root)
#
#
# lst1=tree.findall('nodes/stop')
# for item in lst1:
#     print item.find('name').text
#     print item.find('stop_sn').text
#     print item.find('longitude').text
#     print item.find('latitude').text
#     print item.find('radius').text
#     print item.get('up')
#     print item.get('start')
#
#
